//
//  HeaderView.m
//  DeepBreathing
//
//  Created by rimi on 15/12/19.
//  Copyright © 2015年 rimi. All rights reserved.
//

#import "HeaderView.h"

@interface HeaderView ()

@property(nonatomic,strong)UILabel *label;

@property(nonatomic,strong)UIButton *leftButton;

@property(nonatomic,strong)UIButton *rightButton;





@end


@implementation HeaderView

#pragma mark -- init
-(instancetype)initWithTitleString:(NSString *)string leftImage:(NSString *)leftstring rightImage:(NSString *)rightstring color:(UIColor *)color{

      self = [super init ];

    if(self){
        
        [self WithTitleString:string leftImage:leftstring rightImage:rightstring color:color];
        
        
    }
    return self;
}
#pragma mark -- private methods

-(void)WithTitleString:string leftImage:leftstring rightImage:rightstring color:color{
    
    self.frame = CGRectMake(0, 0, 375, 75);
    
    self.backgroundColor = color;
    
    
    _label = [[UILabel alloc]initWithFrame:CGRectMake(CGRectGetMidX(self.frame) - 60, CGRectGetMidY(self.frame) - 30, 120, 60)];
    
    _label.text = string;
    _label.font = [UIFont systemFontOfSize:20];
    _label.textAlignment = NSTextAlignmentCenter;
    
    [self addSubview:_label];
    
    _leftButton = [UIButton buttonWithType:UIButtonTypeCustom];
    
    [_leftButton setImage:[UIImage imageNamed:leftstring] forState:UIControlStateNormal];
    
    _leftButton.frame = CGRectMake(0, 0, 80, 75);
    
    [_leftButton addTarget:self action:@selector(leftMethod:) forControlEvents:UIControlEventTouchUpInside];
    
    [self addSubview:_leftButton];
    
    
    _rightButton = [UIButton buttonWithType:UIButtonTypeCustom];
    
    [_rightButton setImage:[UIImage imageNamed:rightstring] forState:UIControlStateNormal];
   
        
    _rightButton.frame = CGRectMake(CGRectGetMaxX(self.frame) - 80 , 0, 80, 75);
    
    [_rightButton addTarget:self action:@selector(rightMethod:) forControlEvents:UIControlEventTouchUpInside];
    
    [self addSubview:_rightButton];

    
  }
-(void)leftMethod:(UIButton *)sender{
    
    if (self.LeftDWblock) {
        self.LeftDWblock();
    }
    
    
    
}
-(void)rightMethod:(UIButton *)sender{
    
    if (self.RightDWblock) {
        self.RightDWblock();
    }
    
    
    
    
}
@end
